﻿/*
-----------------------------------------------------------------------------
This source file is part of Cell Cloud.

Copyright (c) 2009-2012 Cell Cloud Team - cellcloudproject@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#ifndef CellStringConverter_h
#define CellStringConverter_h

#include "CellPrerequisites.h"
#include "CellString.h"
#include "CellStringVector.h"

namespace cell
{
/** \addtogroup Core
 *  @{
 */
/** \addtogroup General
 *  @{
 */

/** 字符串转换使用函数。
*/
class _CellExport StringConverter
{
private:
	/** 默认构造。 */
	StringConverter(void);

public:

    /** 转换一个浮点数类型为字符串。 */
    static String toString(float val, unsigned short precision = 6, 
        unsigned short width = 0, char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0));

    /** 转换一个双精度浮点数类型为字符串。 */
    static String toString(double val, unsigned short precision = 6, 
        unsigned short width = 0, char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0));

    /** 转换一个整数类型为字符串。 */
    static String toString(int val, unsigned short width = 0, 
        char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0));

#if CELL_ARCH_TYPE == CELL_ARCHITECTURE_64 || CELL_PLATFORM == CELL_PLATFORM_APPLE || CELL_PLATFORM == CELL_PLATFORM_IOS
	/** 转换一个无符号整型位字符串。 */
	static String toString(unsigned int val, 
		unsigned short width = 0, char fill = ' ', 
		std::ios::fmtflags flags = std::ios::fmtflags(0));

	/** 转换一个 size_t 为字符串。 */
	/*static String toString(size_t val,
		unsigned short width = 0, char fill = ' ',
		std::ios::fmtflags flags = std::ios::fmtflags(0));*/

#if CELL_COMPILER == CELL_COMPILER_MSVC
	/** 转换一个无符号长整型为字符串。 */
	static String toString(unsigned long val, 
		unsigned short width = 0, char fill = ' ', 
		std::ios::fmtflags flags = std::ios::fmtflags(0));
#endif
#else
	/** 转换一个 size_t 为字符串。 */
    static String toString(size_t val, 
        unsigned short width = 0, char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0));

	/** 转换一个无符号长整型为字符串。 */
    static String toString(unsigned long val, 
        unsigned short width = 0, char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0));
#endif
	/** 转换一个长整型为字符串。 */
    static String toString(long val, 
        unsigned short width = 0, char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0));

	/** 转换一个无符号 64 位长整型为字符串。 */
	static String toString(uint64 val, 
		unsigned short width = 0, char fill = ' ', 
		std::ios::fmtflags flags = std::ios::fmtflags(0));

	/** 转换一个布尔型为字符串。
	@param yesNo
		如果设置为 true，则输出结果为 'yes' 或者 'no'，否则输出结果为 'true' 或则 'false'
	*/
    static String toString(bool val, bool yesNo = false);

	/** 检查字符串是否是一个有效的数字值 */
	static bool isNumber(const String& val);

	/** 转换一个字符串为整数型数字。*/
	static int parseInt(const String& val);

	/** 转换一个字符串为无符号整型。 */
	static unsigned int parseUnsignedInt(const String& val);

	/** 转换一个字符串为长整型。 */
	static long parseLong(const String& val);

	/** 转换一个字符串为无符号长整型。 */
	static unsigned long parseUnsignedLong(const String& val);

	/** 转换一个字符串为无符号 64bit 整型。
	*/
	static uint64 parseUnsignedInteger64(const String& val);

	/** 转换一个字符串为布尔型。 */
    static bool parseBool(const String& val);
};

/** @} */
/** @} */
} // end namespace cell

#endif // CellStringConverter_h
